// ========================================================================================================================
// 数据压缩处理：用于在api提交前对数据进行处理，去除无用的信息
// ========================================================================================================================

/**
 * 压缩单张图片
 */
function compressImage(imageVO) {
    return { 
        Id: imageVO.Id,
        UUserId: imageVO.UUserId,
        UserId: imageVO.UserId,
        Type: imageVO.Type,
        Path: imageVO.Path,
        Bucket: imageVO.Bucket,
        FilePostfix: imageVO.FilePostfix,
        Ratio: imageVO.Ratio || 0,
        SWidth: imageVO.SWidth,
        SHeight: imageVO.SHeight
    }
}

/**
 * 压缩图片列表
 */
function compressImageList(imageListVO) {
    for (var i in imageListVO) {
        imageListVO[i] = compressImage(imageListVO[i]);
    }
    return imageListVO;
}

var TalkVO = {
    /**
     * 丢弃前进行压缩
     */
    compressForDiscard: function (talkVO) {
        if (!talkVO) return null;
        talkVO.User = null;
        talkVO.UUser = null;
        var talkBasicVO = talkVO.DraftItem;
        talkBasicVO.Title = '';
        talkBasicVO.Desc = '';
        talkBasicVO.TopPhotos = compressImageList(talkBasicVO.TopPhotos);
        talkBasicVO.Section = [];
        return talkVO;
    },

    /**
     * 保存前进行压缩
     */
    compressForSave: function (talkVO) {
        if (!talkVO) return null;
        talkVO.User = null;
        talkVO.UUser = null;
        var talkBasicVO = talkVO.DraftItem;
        talkBasicVO.TopPhotos = compressImageList(talkBasicVO.TopPhotos);
        for (var i in talkBasicVO.Section) {
            var section = talkBasicVO.Section[i]
            section.Photos = compressImageList(section.Photos);
            var role = section.Role;
            // 压缩段落中的角色内容
            if (role) {
                section.Role = {
                    Id: role.Id,
                    SaveType: role.SaveType
                }
            }
        }
        return talkVO;
    }
}

module.exports = {
    TalkVO: TalkVO
}